package model

import (
	"context"
	"grpc_demo/internal/converter"
	"grpc_demo/internal/dao"
	"grpc_demo/pkg/logger"
)

func LoginModel(ctx context.Context, loginReq converter.LoginReq) (converter.LoginResp, error) {
	var out converter.LoginResp
	user, err := dao.GetUserDaoInstance().Query(loginReq.StuId)
	if err != nil {
		logger.WithContext(ctx).Errorf("Login Query From Dao err :%v", err)
		return out, err
	}
	if loginReq.Password == user.Password {
		out.Message = "登录成功"
		out.Code = 0
	} else {
		out.Message = "账号密码错误"
		out.Code = -1
	}
	return out, err
}
